library Wave11b initializer init requires LegacySystem, DeltaUtils
    
/*
GlobalRegion [1-25] : Smart Grenades
GlobalRegion [26]    : Chain Explosives Area

GlobalPoint [50] : Delta Squad Member Entry Location

CE loc, udg_AirstrikeTarget

*/
    private function ADTVision takes nothing returns nothing
        local player p = GetEnumPlayer()
        call UnitShareVision(udg_ADT[1],p,true)
        call UnitShareVision(udg_ADT[2],p,true)
        call UnitShareVision(udg_ADT[3],p,true)
        call UnitShareVision(udg_ADT[4],p,true)
        set p = null
    endfunction

    private function Wave11d takes nothing returns nothing
        local integer i
        set udg_CurrentWave = 11
        call SetDeltaSpawnEnabled(false)
        //call DisableTrigger(gg_trg_Delta_Wave_Spawn)
        
        call SetCrepitusSpawnEnabled(true)
        
        call GenericActions.execute()
        call StartSound(gg_snd_FattyGrowl)
        call RandomSpawn('uabo',2,udg_Spawn) //Flesh Composite
        call PolledWait(5.)
        call StartSound(gg_snd_ALICEBeep)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 10.00, "|cfff3ad00ALICE|r : Surveillance Sentries have detected large numbers of Flesh Composites." )
        call PolledWait(10.0*udg_Pace)
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : Fuck, this is getting old." )
        call PolledWait(100.0*udg_Pace)
        call SetRevelationSpawnEnabled(true)
        call PolledWait(10.0*udg_Pace)
        
        call ExecuteRegisteredFunction("Wave12a")
        //call Wave12a.execute()
    endfunction

    private function Wave11c takes nothing returns nothing
        local integer i = 1
        local unit u1
        local unit u2
        local unit u3
        local unit u4
        set udg_CurrentWave = 11
        call SetCrepitusSpawnEnabled(true)
        call GenericActions.execute()
        call SetForceAllianceStateBJ( udg_EchoCompany, bj_FORCE_PLAYER[11], bj_ALLIANCE_ALLIED_VISION )
        set u1 = CreateUnit(Player(11),'hrdh',14500.0,12311.0,180.0)
        call ShiftMoveSpeed(u1,210.0)
        call IssuePointOrder( u1,"move",13500.0,12500.0 )
        call TriggerSleepAction(0.)
        set u2 = CreateUnit(Player(11),'hrdh',14500.0,12311.0,180.0)
        call ShiftMoveSpeed(u2,210.0)
        call IssuePointOrder( u2,"move",13300.0,6540.0 )
        call TriggerSleepAction(0.)
        set u3 = CreateUnit(Player(11),'hrdh',14500.0,12311.0,180.0)
        call ShiftMoveSpeed(u3,210.0)
        call IssuePointOrder( u3,"move",12120.0,6910.0 )
        call TriggerSleepAction(0.)
        set u4 = CreateUnit(Player(11),'hrdh',14500.0,12311.0,180.0)
        call ShiftMoveSpeed(u4,210.0)
        call IssuePointOrder( u4,"move",11550.0,9000.0 )
        call PolledWait(10.0)
        call RadioChat(udg_DeltaLeader, 5.0, "|cfff3ad00SSgt. Thompson|r : We've arranged for some pilots to retrieve sensitive equipment from the airfield." )
        call PolledWait(5.)
        call MultiboardSetTitleText( udg_SquadStatus, "Strongpoint and defend the airfield." )
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : My men have set up turret positions at several of the entrances." )
        call PolledWait(2.)
        call StartSound(gg_snd_Construction)
        call PolledWait(4.)
        call StartSound(gg_snd_SatelliteImaging)
        call TriggerSleepAction(0.)
        set udg_ADT[1] = CreateUnit(Player(11),'h00K',11550.0,9000.0,230.0) //West ADT
        call PingMinimapEx(11550.0, 9000.0, 15.0, 255, 0, 0, false)
        call TriggerSleepAction(0.2)
        set udg_ADT[2] = CreateUnit(Player(11),'h00K',12120.0,6910.0,180.0) //South ADT
        call PingMinimapEx(12120.0, 6910.0, 15.0, 255, 0, 0, false)
        call TriggerSleepAction(0.2)
        set udg_ADT[3] = CreateUnit(Player(11),'h00K',13300.0,6540.0,330.0) //East ADT
        call PingMinimapEx(13300.0, 6540.0, 15.0, 255, 0, 0, false)
        call TriggerSleepAction(0.2)
        set udg_ADT[4] = CreateUnit(Player(11),'h00K',13500.0,12500.0,90.0) //North ADT
        call PingMinimapEx(13500.0, 12500.0, 15.0, 255, 0, 0, false)
        set udg_soundpath = "war3mapImported\\AmmoLink.mp3"
        call PlaySoundPath3D.execute()
        call IssuePointOrder( u1,"move",14500.0,12310.0 )
        call IssuePointOrder( u2,"move",14500.0,12310.0 )
        call IssuePointOrder( u3,"move",14500.0,12310.0 )
        call IssuePointOrder( u4,"move",14500.0,12310.0 )
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : Spread out and strongpoint the airfield until the pilots arrive." )
        call PolledWait(5.)
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Strongpoint the Airfield" )
        call QuestSetDescription(udg_CurrentOrders, "Cover all entry points and prevent the airfield from being compromised. Pilots will be arriving shortly to retrieve sensitive components." )
        call ALICE2Text(5.0, "|cff8b864eNew Objective|r : Strongpoint Jefferson Airfield until pilots retrieve equipment." )
        call PolledWait(2.)
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : Get moving." )
        call ForForce( udg_EchoCompany, function ADTVision )
        call PolledWait(5.0)
        call RemoveUnit(u1)
        call RemoveUnit(u2)
        call RemoveUnit(u3)
        call RemoveUnit(u4)
        set u1=null
        set u2=null
        set u3=null
        set u4=null
        set udg_AITarget = gg_unit_hatw_0095 // the tower
        call UnitRemoveAbility(udg_AITarget,'Avul')
        set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        set udg_Boss = CreateUnitAtLoc(Player(14),'U00K',udg_myloc,0) //Minos
        call SuspendHeroXP(udg_Boss,true)
        call RemoveLocation(udg_myloc)
        loop
            exitwhen i>3
            call SpawnRectRandom(gg_rct_ADTSpawnWest,Player(13),'n005',GetRandomInt(1,4)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnWest,Player(13),'n001',udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnEast,Player(13),'n005',GetRandomInt(1,5)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnEast,Player(13),'n001',udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnSouth,Player(13),'n005',GetRandomInt(1,4)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnSouth,Player(13),'n009',udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnNorth,Player(13),'n005',GetRandomInt(1,4)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnNorth,Player(13),'n009',udg_Spawn)
            if GetRandomInt(0,3)==1 then
                call GankMarine(Player(14),'u005',2+udg_Spawn,1700,2500)
            endif
            call PolledWait(12.0*udg_Pace)
            set i=i+1
        endloop
        set i = 1
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : We've found an ammunition stockpile at the central hangar. Load up those turrets!" )
        loop
            exitwhen i>4
            call CreateItem('shas',13683.0,8260.0)
            call TriggerSleepAction(0.)
            set i=i+1
        endloop
        if udg_Players!=0 then
            if GetWidgetLife(udg_AITarget)>0.405 then
                call ExecuteRegisteredFunction("Wave12c")
                //call Wave12c.execute()
            else
                call ADTCleanup.execute()
                call DeltaExit.execute()
                call ExecuteRegisteredFunction("Wave12a")
                //call Wave12a.execute()
                call SetRevelationSpawnEnabled(true)
            endif
        endif
    endfunction

    private function Wave11b takes nothing returns nothing
        set udg_CurrentWave = 11
        call SetDeltaSpawnEnabled(true)
        //call TriggerRegisterTimerEvent( gg_trg_Delta_Wave_Spawn,50.0,true )
        
        call SetCrepitusSpawnEnabled(true)
        
        call GenericActions.execute()
        set udg_IntenseSpawn = 0
        call RandomSpawn('z002',1,udg_Players) //Slasher
        call RandomSpawn('u000',2,GetRandomInt(0, udg_Spawn)) //Futty
        call RadioChat(udg_DeltaLeader, 8.0, "|cfff3ad00SSgt. Thompson|r : I've requested a M242 Chaingun airdrop. We'll move out and retrieve all of its 3 main components." )
        call PolledWait(10.)
        call RadioChat(udg_DeltaLeader, 8.0, "|cfff3ad00SSgt. Thompson|r : The first part is on its way." )
        call MultiboardSetTitleText( udg_SquadStatus, "Retrieve M242 Components." )
        call PolledWait(10.)
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Retrieve M242 Components" )
        call QuestSetDescription(udg_CurrentOrders, "Echo Company and 1st SFOD-D will coordinate a retrieval of M242 Chaingun components and set it up to bolster sector defenses." )
        call ALICE2Text(5., "|cff8b864eNew Objective|r : Retrieve M242 Components." )
        call PolledWait(5.)
        call M242Drop.execute()
        call PolledWait(160.*udg_Pace)
        if udg_Players!=0 then
            if udg_DeltaLeader==null then
                call DeltaExit.execute()
                call ExecuteRegisteredFunction("Wave12a")
                //call Wave12a.execute()
                call SetDeltaSpawnEnabled(false)
                //call DisableTrigger(gg_trg_Delta_Wave_Spawn)
                call SetRevelationSpawnEnabled(true)
            else
                call ExecuteRegisteredFunction("Wave12b")
                //call Wave12b.execute()
            endif
        endif
    endfunction

    private function init takes nothing returns nothing
        call RegisterFunction("Wave11b", function Wave11b)
        call RegisterFunction("Wave11c", function Wave11c)
        call RegisterFunction("Wave11d", function Wave11d)
                        
        //call ExecuteRegisteredFunction("Wave10b")
    endfunction
endlibrary